//
//  NSString+PYCreateUrl.m
//  catuncel
//
//  Created by Jim on 2017/12/3.
//  Copyright © 2017年 Jim. All rights reserved.
//

#import "NSString+PYCreateUrl.h"

@implementation NSString (PYCreateUrl)

- (NSURL *)qiniuUrl
{
    NSString *urlString = [NSString stringWithFormat:@"http://pu.imquanzi.com/%@", self];
    
    urlString = [urlString stringByReplacingOccurrencesOfString:@"\\" withString:@"/"];
    
    NSLog(@"拼接后的url:%@", urlString);
    
    NSString *encodedString = [urlString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    
    return [NSURL URLWithString:encodedString];
}

- (NSURL *)qiniuVideoUrl
{
    NSString *urlString = [NSString stringWithFormat:@"http://pu.imquanzi.com/%@", self];
    
    urlString = [urlString stringByReplacingOccurrencesOfString:@"\\" withString:@"/"];
    
    NSLog(@"拼接后的url:%@", urlString);
    
    NSString *encodedString = [urlString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    
    return [NSURL URLWithString:encodedString];
}

- (NSURL *)qiniuImageUrlWithWidth:(CGFloat)width
{
    CGFloat scale = [UIScreen mainScreen].scale;
    
    NSString *urlString = [NSString stringWithFormat:@"%@?imageView2/2/w/%d", self, (int)(width * scale)];
    
    urlString = [urlString stringByReplacingOccurrencesOfString:@"\\" withString:@"/"];

    NSLog(@"拼接后的url:%@", urlString);

    NSString *encodedString = [urlString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    
    return [NSURL URLWithString:encodedString];
}

- (NSURL *)imquanziUrl
{
    NSString *urlString = [NSString stringWithFormat:@"http://www.imquanzi.com/images/%@", self];
    
    urlString = [urlString stringByReplacingOccurrencesOfString:@"\\" withString:@"/"];

    NSLog(@"拼接后的url:%@", urlString);
    
    NSString *encodedString = [urlString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];

    return [NSURL URLWithString:encodedString];
}

- (NSURL *)thumbnailUrl
{
    CGFloat scale = [UIScreen mainScreen].scale;
    
    CGFloat width = SCREEN_WIDTH * scale / 3;
    
    NSString *urlString = [NSString stringWithFormat:@"http://oxfr2hr4h.bkt.clouddn.com/%@?imageView2/2/w/%d", self, (int)width];
    
    urlString = [urlString stringByReplacingOccurrencesOfString:@"\\" withString:@"/"];
    
    NSLog(@"拼接后的url:%@", urlString);
    
    NSString *encodedString = [urlString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    
    return [NSURL URLWithString:encodedString];
}

- (NSURL *)bigThumbnailUrl
{
    CGFloat scale = [UIScreen mainScreen].scale;
    
    CGFloat width = SCREEN_WIDTH * scale * 2 / 3;
    
    NSString *urlString = [NSString stringWithFormat:@"http://oxfr2hr4h.bkt.clouddn.com/%@?imageView2/2/w/%d", self, (int)width];
    
    urlString = [urlString stringByReplacingOccurrencesOfString:@"\\" withString:@"/"];
    
    NSLog(@"拼接后的url:%@", urlString);
    
    NSString *encodedString = [urlString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    
    return [NSURL URLWithString:encodedString];
}

@end
